package com.asap.demo.ck.util;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.util.HashMap;
import java.util.Map;

public class PropTransformMap {
	private static final Logger logger = LoggerFactory.getLogger(PropTransformMap.class);

	private static PropTransformMap prop2Map = new PropTransformMap();

	private PropTransformMap() {
	}

	public static PropTransformMap getInstance() {
		return prop2Map;
	}


	public Map<String, String> readConfigMap(String path) {
		try (FileInputStream fis = new FileInputStream(new File(path));
			 InputStreamReader isr = new InputStreamReader(fis);
			 BufferedReader br = new BufferedReader(isr)) {
			String row = null;
			Map<String, String> sMap = new HashMap<String, String>();
			while (null != (row = br.readLine())) {
				if (!row.equals("")) {
					if (row.startsWith("#")) {
						continue;
					}
					String key = row.substring(0, row.indexOf("="));
					String value = row.substring(row.indexOf("=") + 1, row.length());
					sMap.put(key, value);
				}
			}
			return sMap;
		} catch (Exception e) {
			logger.error("", e);
		}
		return null;
	}

}
